import {Injectable} from '@angular/core';
import {PageVo} from '../entity/page-vo';
import {BehaviorSubject} from 'rxjs';

@Injectable({
    providedIn: 'root'
})
export class PageVoService {
    private pageBehavior = new BehaviorSubject({});

    currentPageVo = this.pageBehavior.asObservable();

    ownerBehavior = new BehaviorSubject({});

    ownerObservable = this.ownerBehavior.asObservable();

    private pageVo: PageVo;

    constructor() {
    }

    public setPageVo(pageVo: PageVo) {
        this.pageVo = pageVo;
        if (pageVo.leftMenuId === 'index' || pageVo.leftMenuId === 'setting') {
            this.ownerBehavior.next([]);
        }

        return this.pageBehavior.next(this.pageVo);
    }

    public getPageVo(): PageVo {
        if (this.pageVo == null) {
            this.pageVo = <PageVo>{};
        }
        return this.pageVo;
    }
}
